<?php

namespace App\Http\Controllers\Rent;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Qiniu\Auth;
class RentController extends Controller
{
    //租人首页
    public function index(){

        //members t1  rent_project t2  ims_paylog t3
        //筛选--------------------------------------------------------------------------------------
        $where = ' where 1 = 1 ';
        $where = '';
        if(isset($_POST['sex']) && !empty($_POST['sex'])){
            $where .= " and t1.sex =" .$_POST['sex'];
        }

        if(isset($_POST['findid']) && !empty($_POST['findid'])){
            $where .= " and t1.id =" .$_POST['findid'];
        }

        if(isset($_POST['project']) && !empty($_POST['project'])){
            $arr = explode(',',$_POST['project']);
            $num = count($arr);
            $where = " and ";
            foreach($arr as $k=> $v){
                if($num == 1){
                    $where .= "  t2.project like '%" .$arr[$k]."%'";
                }else{
                    if($k == 0){
                        $where .= " (t2.project like '%" .$arr[$k]."%'";
                    }else{
                        $where .= " or t2.project like '%" .$arr[$k]."%')";
                    }
                }
            }
        }
        if(isset($_POST['price']) && !empty($_POST['price'])){
            if(strstr($_POST['price'],'以下')){
                $str = substr($_POST['price'],0,strpos($_POST['price'], '以下'));
                $where .=" and t2.price <".$str;
            }else if(strstr($_POST['price'],'以上')){
                $str = substr($_POST['price'],0,strpos($_POST['price'], '以上'));
                $where .=" and t2.price >".$str;
            }else if(strstr($_POST['price'],'-')){
                $arr = explode('-',$_POST['price']);
                $str1 = $arr[0];
                $str2 = $arr[1];
                $where .=" and t2.price >".$str1." and t2.price < $str2";
            }
        }
        if(isset($_POST['city']) && !empty($_POST['city'])){
            $where .= " and t1.city like '%" .$_POST['city']."%'";
        }

        if(isset($_POST['day']) && !empty($_POST['day'])){
            $arr = explode(',',$_POST['day']);
            $num = count($arr);
            $where = " and ";
            foreach($arr as $k=> $v){
                if($num == 1){
                    $where .= "  t1.free_time like '%" .$arr[$k]."%'";
                }else{
                    if($k == 0){
                        $where .= " (t1.free_time like '%" .$arr[$k]."%'";
                    }else{
                        $where .= " or t1.free_time like '%" .$arr[$k]."%')";
                    }
                }
            }
        }

        if(isset($_POST['time']) && !empty($_POST['time'])){
            if($_POST['time'] == '白天'){
                $where .= " and ((t1.free_start>='06:00:00' and t1.free_start <= '18:00:00') or (t1.free_end>='06:00:00' and t1.free_end <= '18:00:00')) ";
            }else if($_POST['time'] == '晚上'){
                $where .= " and ((t1.free_start>='18:00:00' or t1.free_start <= '06:00:00') or (t1.free_end>='18:00:00' or t1.free_end <= '06:00:00')) ";
            }
        }
        //------------------------------------------------------------------------------------------
        $pagesize = 6;
        $page = isset($_POST['page']) ? $_POST['page'] : 1;
        $start = ($page-1)*$pagesize;
        //获取用户地理位置
        //分为附近 推荐 最新 三个栏目
        //@param  group [nearby/recommend/new]
        //筛选 screen
        $group = $_POST['group'];
//        $screen = $_POST['screen'];
        if('nearby' == $group){
            $id = $_POST['id'];
            $lng = $_POST['lng'];//经纬度
            $lat = $_POST['lat'];
            DB::table('members')->where('id',$id)->update(array('lng'=>$lng,'lat'=>$lat));
            //取附近10W米内用户
//            $x = 0.00000681617*100000;
            //取附近1W米内用户
            $a = 0.00000680489*10000;
            $x1 = $lng+$a;
            $y1 = $lng-$a;
            $x2 = $lat+$a;
            $y2 = $lat-$a;
            $update_top_end = DB::table('members')->where('top','<',time())->update(array('top'=>null));
            $sql = "select t1.id,t1.sex,t1.top,t1.image,t1.top_num,t1.nickname,t1.lng,t1.lat,t2.project,t2.price,t2.company from ims_members as t1 left join ims_rental_project as t2 on t1.id = t2.uid where (t1.top>".time()." or t1.top_num is not null or (t1.lng < $x1 and t1.lng > $y1 and t1.lat < $x2 and t1.lat > $y2)) and t1.id !={$id} ".$where;
            $data = DB::select($sql);

            if(!empty($data)){
                foreach($data as $k=>$v){
                    $a = (array)$v;
                    $data[$k] = $a;
                }
                // dump($data);die;
                foreach($data as $k=>$row){
                    if(!empty($row['top_num'])){
                        $topArr= json_decode($row['top_num'],true);
                        if($topArr['now'] < (int)$topArr['count']){
                            $data[$k]['top_num'] = 1;
                        }else{
                            $data[$k]['top_num'] = 0;
                        }
                    }else{
                        $data[$k]['top_num'] = 0;
                    }
                    $n = floor(getdistance($lng,$lat,$row['lng'],$row['lat']))/1000;
                    $data[$k]['distance'] = sprintf("%.1f", $n).'km';
                    unset($data[$k]['lng']);
                    unset($data[$k]['lat']);
                }
                
                array_multisort(array_column($data,'top'),SORT_DESC,array_column($data,'top_num'),SORT_DESC,array_column($data,'distance'),SORT_ASC,$data);
                $result = array_slice($data,$start,$pagesize);
                array_walk_recursive($result, function (& $val, $key ) {
                    if ($val === null) {
                        $val = '';
                    }
                });
                return json_encode(array('r'=>1,'result'=>$result));
            }else{
                return json_encode(array('r'=>-1,'msg'=>'暂无数据！'));
            }

        }else if('recommend' == $group){
        	$update_top_end = DB::table('members')->where('top','<',time())->update(array('top'=>null));
            $sql = "SELECT t1.id,t1.sex,t1.nickname,t1.top,t1.top_num,t1.image,t2.project,t2.price ,t2.company,count(t3.id) ,sum(t3.price) FROM `ims_members`as t1 left join ims_rental_project as t2 on t1.id = t2.id left join ims_paylog as t3 on t1.id = t3.uid where 1 = 1".$where." group by t1.id order by t1.top desc,t1.top_num desc,sum(t3.price) desc ,count(t3.id) desc , t1.id desc limit $start,$pagesize";
            $logs = DB::select($sql);
            if(!empty($logs)){
                foreach($logs as $k=>$v){
                    $a = (array)$v;
                    $logs[$k] = $a;
                }
                array_walk_recursive($logs, function (& $val, $key ) {
                    if ($val === null) {
                        $val = '';
                    }
                });
                return json_encode(array('r'=>1,'result'=>$logs));
            }else{
                return json_encode(array('r'=>-1,'msg'=>'暂无数据'));
            }
        }else if('new' == $group){

        }
    }

    public function findid(){
        $findid = $_POST['findid'];
        $sql = "select t1.id,t1.sex,t1.image,t1.nickname,t2.project,t2.price,t2.company from ims_members as t1 left join ims_rental_project as t2 on t1.id = t2.uid where t1.id = $findid ";
        $data = DB::select($sql);
        if(!empty($data)){
            foreach($data as $k=>$v){
                $a = (array)$v;
                $data[$k] = $a;
            }
            array_walk_recursive($data, function (& $val, $key ) {
                if ($val === null) {
                    $val = '';
                }
            });
            return json_encode(array('r'=>1,'result'=>$data));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'用户不存在！'));
        }

    }

    public function select(){
        $logs = DB::table('project')->where('class',1)->orwhere('class',4)->get()->map(function($v){return (array)$v;})->toarray();
        $arr = array('project'=>array(),'price'=>array());
        if(!empty($logs)){
        	foreach($logs as $row){
	            if($row['class'] == 1){
	                $arr['project'][] = $row['project'];
	            }elseif($row['class'] == 4){
	                $arr['price'][] = $row['project'];
	            }
        	}
	        array_unshift($arr['project'],'全部');
	        array_unshift($arr['price'],'全部');
        }
        
        return json_encode(array('r'=>1,'result'=>$arr));
    }

    // 个人信息
    public function info(){
        if(isset($_POST['id']) && $_POST['id'] != ''){
        	$id = $_POST['id'];
			if(isset($_POST['uid']) && $_POST['uid'] != ''){
	            $uid = $_POST['uid'];
	            $myInfo = (array)DB::table('members')->select('lng','lat')->where('id',$id)->first();
	            $data = (array)DB::table('members')->select('id','nickname','age','sex','personal','job','height','weight','free_time','hobby','fans','lng','lat','city','weixin','picture','idcard','zhima')->where('id',$uid)->first();
	            
                if(!empty($myInfo['lng'])&&!empty($myInfo['lat'])&&!empty($data['lng'])&&!empty($data['lat'])){
                    $n = floor(getdistance($myInfo['lng'],$myInfo['lat'],$data['lng'],$data['lat']))/1000;
                    $data['distance'] = sprintf("%.1f", $n).'km';
                }else{
                    $data['distance'] = '';
                }
                    // $n = floor(getdistance($myInfo['lng'],$myInfo['lat'],$data['lng'],$data['lat']))/1000;
                    // $data['distance'] = sprintf("%.1f", $n).'km';
	            unset($data['lng']);
	            unset($data['lat']);
				$bool = (array)DB::table('fans')->where('uid',$uid)->where('fid',$id)->first();
                if(!empty($bool)){
                   $data['isMutual'] = 1;
                }else{
                   $data['isMutual'] = 0;
                }

                $wxprice = (array)DB::table('project')->select('project')->where('class','9')->first();
                if(!empty($wxprice)){
                    $wxprice = $wxprice['project'];
                }else{
                    $wxprice = 20;
                }
                
                $data['wxprice'] = $wxprice;
	            $data1 = DB::table('thumb')
	                ->select('url','key','image')->where('uid',$uid)->where('status','>',0)
	                ->orderby('status','desc')->orderby('key','asc')->get()->map(function ($value) {
	                    return (array)$value;
	                })->toArray();


	            if(!empty($data1)){
	                // foreach($data1 as $row){
	                //     $data['url'][] = $row;
	                // }
                    $data['url'] = $data1;
	            }else{
	                $data['url'] = (object)array();
	            }

	            //需求动态部分
	            $data2 = (array)DB::table('rent_circle')->select('text','create_time','class','url')->where('uid',$uid)->orderBy('create_time','desc')->first();
	            if(!empty($data2)){
	                $data['need'] = $data2;
	            }else{
	                $data['need'] = (object)array();
	            }

	            //出租项目部分
	            $data3 = (array)DB::table('rental_project')->select('project','price','company')->where('uid',$uid)->first();
	            if(!empty($data3)){
	                $data['rental_project'] = $data3;
	            }else{
	                $data['rental_project'] = (object)array();
	            }
	            //------------------TA的评价----------------------------
	            $sql = "select t1.image,t1.nickname ,t2.comment from ims_members as t1 left join ims_comment as t2 on t1.id = t2.fid where t2.uid = $uid order by t2.create_time desc";
	            $data4 = DB::select($sql);
	            if(!empty($data4)){
	                foreach($data4 as $k=>$v){
	                    $a = (array)$v;
	                    $data4[$k] = $a;
	                }
	                $data['comment'] = $data4;
	            }else{
	                $data['comment'] = (object)array();
	            }
	            array_walk_recursive($data, function (& $val, $key ) {
	                if ($val === null) {
	                    $val = '';
	                }
            	});
	            //END
	            return json_encode(array('r'=>1,'result'=>$data));
	        }else{
	            $data = (array)DB::table('members')->select('id','nickname','age','sex','personal','job','height','weight','free_time','hobby','fans','city','weixin','picture','idcard','zhima')->where('id',$id)->first();
	            $data['distance'] = '';
	            $data1 = DB::table('thumb')
	                ->select('url','key','image')->where('uid',$id)->where('status','>',0)
	                ->orderby('status','desc')->orderby('key','asc')->get()->map(function ($value) {
	                    return (array)$value;
	                })->toArray();
	            if(!empty($data1)){
	                // foreach($data1 as $row){
                    //     $data['url'][] = $row;
                    // }
                    $data['url'] = $data1;
	            }else{
	                $data['url'] = array();
	            }

	            $data2 = (array)DB::table('rent_circle')->select('text','create_time','class','url')->where('uid',$id)->orderBy('create_time','desc')->first();
	            if(!empty($data2)){
	                $data['need'] = $data2;
	            }else{
	                $data['need'] = (object)array();
	            }

	            //出租项目部分
	            $data3 = (array)DB::table('rental_project')->select('project','price','company')->where('uid',$id)->first();
	            if(!empty($data3)){
	                $data['rental_project'] = $data3;
	            }else{
	                $data['rental_project'] = (object)array();
	            }
	            //------------------TA的评价----------------------------
	            $sql = "select t1.image,t1.nickname ,t2.comment from ims_members as t1 left join ims_comment as t2 on t1.id = t2.fid where t2.uid = $id order by t2.create_time desc";
	            $data4 = DB::select($sql);
	            if(!empty($data4)){
	                foreach($data4 as $k=>$v){
	                    $a = (array)$v;
	                    $data4[$k] = $a;
	                }
	                $data['comment'] = $data4;
	            }else{
	                $data['comment'] = (object)array();
	            }
	            array_walk_recursive($data, function (& $val, $key ) {
	                if ($val === null) {
	                    $val = '';
	                }
            	});
	            //END
	            return json_encode(array('r'=>1,'result'=>$data));
	        }
        }else{
        	if(isset($_POST['uid']) && $_POST['uid'] != ''){
	            $uid = $_POST['uid'];
	            $data = (array)DB::table('members')->select('id','nickname','age','sex','personal','job','height','weight','free_time','hobby','fans','city','weixin','picture','idcard','zhima')->where('id',$uid)->first();
	            $data['distance'] = '';
	            $data1 = DB::table('thumb')
	                ->select('url','key','image')->where('uid',$uid)->where('status','>',0)
	                ->orderby('status','desc')->orderby('key','asc')->get()->map(function ($value) {
	                    return (array)$value;
	                })->toArray();
	            if(!empty($data1)){
                    $data['url'] = $data1;
	            }else{
	                $data['url'] = array();
	            }
	            $data['isMutual'] = 0;

                $wxprice = (array)DB::table('project')->select('project')->where('class','9')->first();
                if(!empty($wxprice)){
                    $wxprice = $wxprice['project'];
                }else{
                    $wxprice = 20;
                }
                
                $data['wxprice'] = $wxprice;
	            //需求动态部分
	            $data2 = (array)DB::table('rent_circle')->select('text','create_time','class','url')->where('uid',$uid)->orderBy('create_time','desc')->first();
	            if(!empty($data2)){
	                $data['need'] = $data2;
	            }else{
	                $data['need'] = (object)array();
	            }

	            //出租项目部分
	            $data3 = (array)DB::table('rental_project')->select('project','price','company')->where('uid',$uid)->first();
	            if(!empty($data3)){
	                $data['rental_project'] = $data3;
	            }else{
	                $data['rental_project'] = (object)array();
	            }
	            //------------------TA的评价----------------------------
	            $sql = "select t1.image,t1.nickname ,t2.comment from ims_members as t1 left join ims_comment as t2 on t1.id = t2.fid where t2.uid = $uid order by t2.create_time desc";
	            $data4 = DB::select($sql);
	            if(!empty($data4)){
	                foreach($data4 as $k=>$v){
	                    $a = (array)$v;
	                    $data4[$k] = $a;
	                }
	                $data['comment'] = $data4;
	            }else{
	                $data['comment'] = (object)array();
	            }
	            array_walk_recursive($data, function (& $val, $key ) {
	                if ($val === null) {
	                    $val = '';
	                }
            	});
	            //END
	            return json_encode(array('r'=>1,'result'=>$data));
	        }
        }
        
    }
    //显示评论
    public function showComment(){
        $logs = DB::table('project')->where('class',5)->get()->map(function($v){return $v->project;})->toArray();
        return json_encode(array('r'=>1,'result'=>$logs));
    }
    //填写评论
    public function comment(){
        $data = array(
            'uid' =>$_POST['uid'],
            'fid' =>$_POST['fid'],
            'comment' =>$_POST['comment'],
            'create_time'=>time()
        );
        $bool = DB::table('comment')->insert($data);
        if($bool){
            return json_encode(array('r'=>1,'msg'=>'评论成功！'));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'评论失败！'));
        }
    }



    //------------------------------------上传头像相册-----------------------------------------------------------------
    /*public function thumb(Request $request){
        //class  1.相册 2.头像 3，视频
        $file = $request->file('thumb');
        $id = $_POST['id'];
        $class = $_POST['class'];
        if($file->isValid()){
            $originalName = $file->getClientOriginalName(); // 文件原名
            $ext = $file->getClientOriginalExtension();     // 扩展名
            $realPath = $file->getRealPath();   //临时文件的绝对路径
            $type = $file->getClientMimeType();     // image/jpeg
            // 上传文件
            $filename = date('y-m-d').'-'.uniqid() . '.' . $ext;
            // 使用我们新建的uploads本地存储空间（目录）
            //这里的uploads是配置文件的名称
            $bool = Storage::disk('uploads')->put($filename, file_get_contents($realPath));
            if($bool){
                //如果头像以存在则替换
                $path =getDomain().'uploads/'.$filename;
                $data  = array(
                    'uid'=>$id,
                    'url'=>$path,
                    'class'=>$class,
                    'status'=>0,
                    'create_time'=>time()
                );
                $log = DB::table('thumb')->insert($data);
            }else{
                return json_encode(array('r'=>-1,'msg'=>'图片上传失败！'));
            }
        }
    }*/
    //------------------------------------上传图像视频Token------------------------------------------------------------
    public function qiniu_token(){
        require '../vendor/autoload.php';
        $accessKey = 'Pgc1WYp5XrfK5M9RzxL4S8road_gUpEb4OGRKnLz';
        $secretKey = 'SHipDSUxqjwhUhdTM0NxsEqDxNIYmXs3n_KeUm1-';
        $auth = new Auth($accessKey, $secretKey);
        $bucket = 'yuezu';
        // 生成上传Token
        $token = $auth->uploadToken($bucket);
        $domain = qiniuDomain();
        return json_encode(array('r'=>1,'token'=>$token,'domain'=>$domain));
    }

    public function thumb(){
        $image = isset($_POST['image'])?$_POST['image']:'';
        $data = array(
            'uid'=>$_POST['uid'],//用户ID
            'url'=>$_POST['url'],
            'class'=>$_POST['class'],
            'status'=>0,
            'image' =>$image,
            'key'=>$_POST['key'],
            'create_time'=>time()
        );
        $log = (array)DB::table('thumb')->where('uid',$_POST['uid'])->where('key',$_POST['key'])->first();
        if(empty($log)){
            $bool = DB::table('thumb')->insert($data);
            if($_POST['key'] == 9){
                DB::table('members')->where('id',$uid)->update(array('picture'=>2));
            }
            if($bool){
                return json_encode(array('r'=>1,'msg'=>'添加成功！'));
            }else{
                return json_encode(array('r'=>-1,'msg'=>'添加失败！'));
            }

        }else{
            $bool = DB::table('thumb')->where('uid',$_POST['uid'])->where('key',$_POST['key'])->update(array('url'=>$_POST['url'],'status'=>0));
            if($_POST['key'] == 9){
                DB::table('members')->where('id',$uid)->update(array('picture'=>2));
            }
            if($bool){
                return json_encode(array('r'=>1,'msg'=>'修改成功！'));
            }else{
                return json_encode(array('r'=>-1,'msg'=>'修改失败！'));
            }
        }

    }

    //-----------------------------4.用户手机号登陆--------------------------------------------------------------------
    public function login(){
        $mobile = $_POST['mobile'];
        $pwd = $_POST['pwd'];
        $user = (array)DB::table('user')->where('mobile',$mobile)->first();
        if(!empty($user) && $user['pwd'] == MD5($pwd)){
            //更新用户最后操作时间
            $info = (array)DB::table('members')->select('id','mobile','nickname')->where('mobile',$mobile)->first();
            $token = MD5($info['id'].time());
            $token_end = time()+3600*24*30;
            $data = array('last_time'=>time(),'token'=>$token,'token_end'=>$token_end);
            $bool = DB::table('members')->where('mobile',$mobile)->update($data);
            $info['token'] = $token;
            array_walk_recursive($info, function (& $val, $key ) {
                if ($val === null) {
                    $val = '';
                }
            });
            if($bool && !empty($info)){
                session()->put('info',$info);
                return json_encode(array('r'=>1,'result'=>$info));
            }else{
                return json_encode(array('r'=>-1,'msg'=>'登陆失败'));
            }
        }else{
            return json_encode(array('r'=>-1,'msg'=>'用户名不存在或密码错误!'));
        }
    }
    //-----------------------------------------------------------------------------------------------------------------

    //------------------------------5-6.手机号注册---------------------------------------------------------------------
    public function get_code(){
        //拿到手机号先查询该手机号是否注册过
        $mobile = $_POST['mobile'];
        $info = (array)DB::table('user')->where('mobile',$mobile)->first();
        if(empty($info)){
            //没被注册则发送验证码注册账号
            $code = mt_rand(1000,9999);
            $result = send_msg($mobile,$code);
            if(1 == $result['r']){
                //如果短信发送成功则 存code用来验证 验证码有效时间10分钟
                $bool = DB::insert("insert into ims_code(mobile,code,time) values('".$mobile."','".$code."','".(time()+600)."')");
                if(true ==$bool){
                    return json_encode(array('r'=>1,'msg'=>"验证码获取完毕"));
                }
            }else{
                return json_encode(array('r'=>-1,'msg'=>$result['msg']));
            }
        }else{
            return json_encode(array('r'=>-1,'msg'=>'该手机号已被注册！'));
        }
    }

    public function zhuce(){
        $k_mobile = $_POST['mobile'];
        $k_pwd = $_POST['pwd'];
        $k_code = $_POST['code'];
        $info = (array)DB::table('user')->where('mobile',$k_mobile)->first();
        if(empty($info)){
            $db_code = (array)DB::table('code')->where('mobile',$k_mobile)->orderby('time','desc')->first();
            if($k_code == $db_code['code'] && $db_code['time'] >=time()){
                $bool1 = DB::insert("insert into ims_user(mobile,pwd,create_time,last_time) values('".$k_mobile."','".MD5($k_pwd)."','".time()."','".time()."')");
                $create_time = time();
                $last_time = time();
                $bool2 = DB::insert("insert into ims_members(mobile,create_time,last_time) values($k_mobile,$create_time,$last_time)");
                if(true == $bool1 && true == $bool2){
                    return json_encode(array('r'=>1,'mgs'=>'注册成功！'));
                }
            }else{
                return json_encode(array('r'=>-1,'msg'=>'验证码错误或超时！'));
            }
        }else{
            return json_encode(array('r'=>-1,'msg'=>'该手机号已被注册！'));
        }

    }

//    public function add_info(){
//        $k_mobile = $_POST['mobile'];
//        $info = (array)DB::table('members')->where('mobile',$k_mobile)->first();
//        if(empty($info)){
//            $nickname = $_POST['nickname'];
//            $age = $_POST['age'];
//            $job = $_POST['job'];
//            $height = $_POST['height'];
//            $weight= $_POST['weight'];
//            /*$nickname = '续写青春';
//            $age = '26';
//            $job='php工程师';
//            $height= 176;
//            $weight= 70;*/
//            $create_time = time();
//            $last_time = time();
//            $bool = DB::insert("insert into ims_members(nickname,mobile,age,job,height,weight,create_time,last_time) values('".$nickname."','".$k_mobile."','".$age."','".$job."','".$height."','".$weight."','".$create_time."','".$last_time."')");
//            if(true == $bool){
//                return json_encode(array('r'=>1,'mgs'=>'基本信息已提交！'));
//            }
//        }else{
//            return json_encode(array('r'=>-1,'msg'=>'该手机号已存在！'));
//        }
//    }
    //-----------------------------------------------------------------------------------------------------------------

    //-----------------------------------7.找回密码--------------------------------------------------------------------
    public function forgot_code(){
        $mobile = $_POST['mobile'];
        $info = (array)DB::table('user')->where('mobile',$mobile)->first();
        if(empty($info)){
            return json_encode(array('r'=>-1,'msg'=>"该用户不存在！"));
        }else{
            $code = mt_rand(1000,9999);
            $result = send_msg($mobile,$code);
            if(1 == $result['r']){
                //如果短信发送成功则 存code用来验证 验证码有效时间10分钟
                $bool = DB::insert("insert into ims_code(mobile,code,time) values('".$mobile."','".$code."','".(time()+600)."')");
                if(true ==$bool){
                    return json_encode(array('r'=>1,'msg'=>"验证码获取完毕"));
                }
            }else{
                return json_encode(array('r'=>-1,'msg'=>$result['msg']));
            }
        }
    }

    public function forgot_pwd(){
        $mobile = $_POST['mobile'];
        $code = $_POST['code'];
        $pwd = $_POST['pwd'];
        $db_code = (array)DB::table('code')->where('mobile',$mobile)->orderby('time','desc')->first();
        if($code == $db_code['code'] && $db_code['time'] >=time()){
            $bool = DB::table("user")->where('mobile',$mobile)->update(array('pwd'=>MD5($pwd)));
            if(true == $bool){
                return json_encode(array('r'=>1,'mgs'=>'密码修改成功！'));
            }
        }else{
            return json_encode(array('r'=>-1,'msg'=>'验证码错误或超时！'));
        }
    }
    //-----------------------------------------------------------------------------------------------------------------

    //----------------------------------8.修改手机号-------------------------------------------------------------------
    //在这之前调获取验证码接口 get_code
    public function edit_phone(){
        $old_mobile = $_POST['old_mobile'];
        $mobile = $_POST['mobile'];//   新手机号
        $code = $_POST['code'];
        $db_code = (array)DB::table('code')->where('mobile',$mobile)->orderby('time','desc')->first();
        if($code == $db_code['code'] && $db_code['time'] >=time()){
            $bool = DB::table("user")->where('mobile',$old_mobile)->update(array('mobile'=>$mobile));
            $bool2 = DB::table("members")->where('mobile',$old_mobile)->update(array('mobile'=>$mobile));
            if(true == $bool && true == $bool2){
                return json_encode(array('r'=>1,'mgs'=>'手机号修改成功！'));
            }else{
                return json_encode(array('r'=>-1,'mgs'=>'手机号修改失败！'));
            }
        }else{
            return json_encode(array('r'=>-1,'msg'=>'验证码错误或超时！'));
        }
    }
    //-----------------------------------------------------------------------------------------------------------------

    //----------------------------------9-10.出租项目与价格------------------------------------------------------------
    public function show_project(){
        $id = $_POST['id'];
        $data1 = DB::table('project')->select('project')->where('class',1)->get()
            ->map(function($value){return (array)$value;})->toArray();
        $arr1 = array();

        if(!empty($data1)){
            foreach($data1 as $row){
                $arr1[] = $row['project'];
            }
        }



        $data2 = (array)DB::table('rental_project')->select('project','price','company')->where('uid',$id)->first();
        $arr2 = array();
        $price = '';
        $company = '';
        if(!empty($data2)){
            $arr2 = explode(',',$data2['project']);
            $price = $data2['price'];
            $company = $data2['company'];
        }
        $a = array_diff($arr2,$arr1);
        if(!empty($a)){
            foreach ($a as $key => $v) {
                $arr1[] = $v;
            }
        }
        return json_encode(array('r'=>1,'result'=>array('project'=>$arr1,'select'=>$arr2,'price'=>$price,'company'=>$company)));
    }

    public function add_project(){
        $id = $_POST['id'];
        $project = $_POST['project'];
        $price = $_POST['price'];
        $company = $_POST['company'];
        if(!empty($id) && !empty($project) && !empty($price) && !empty($company)){
            $log = (array)DB::table('rental_project')->where('uid',$id)->first();
            if(empty($log)){
                $bool = DB::table('rental_project')->insert(array('uid'=>$id,'project'=>$project,'price'=>$price,'company'=>$company));
            }else{
                $bool = DB::table('rental_project')->where('uid',$id)->update(array('project'=>$project,'price'=>$price,'company'=>$company));
            }
            if(true == $bool){
                return json_encode(array('r'=>1,'msg'=>'编辑出租项目成功!'));
            }else{
                return json_encode(array('r'=>-1,'msg'=>'编辑出租项目失败!'));
            }
        }else{
            return json_encode(array('r'=>-1,'msg'=>'信息不完整！'));
        }

    }
    //-----------------------------------------------------------------------------------------------------------------

    //---------------------------------11-12个人特长-------------------------------------------------------------------
    public function show_hobby(){
        $id = $_POST['id'];
        $data1 = DB::table('project')->select('project')->where('class',3)->get()
            ->map(function($value){return (array)$value;})->toArray();
        $arr1 = array();
        if(!empty($data1)){
            foreach($data1 as $row){
                $arr1[] = $row['project'];
            }
        }
        $data2 = (array)DB::table('members')->select('hobby')->where('id',$id)->first();
        $arr2 =array();
        if(!empty($data2['hobby'])){
            $arr2 = explode(',',$data2['hobby']);
        }
        if(!empty($arr2)){
            $a = array_diff($arr2,$arr1);
            if(!empty($a)){
                foreach ($a as $key => $v) {
                    $arr1[] = $v;
                }
            }
        }
        return json_encode(array('r'=>1,'result'=>array('hobby'=>$arr1,'select'=>$arr2)));
    }

    public function add_hobby(){
        $id = $_POST['id'];
        $hobby = $_POST['hobby'];
        $bool = DB::table('members')->where('id',$id)->update(array('hobby'=>$hobby));
        if($bool){
            return json_encode(array('r'=>1,'msg'=>'编辑个人特长成功！'));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'编辑个人特长失败！'));
        }
    }
    //-----------------------------------------------------------------------------------------------------------------

    //---------------------------------13编辑职业----------------------------------------------------------------------
    public function show_job(){
        $id = $_POST['id'];
        $data1 = DB::table('project')->select('project')->where('class',2)->get()
            ->map(function($value){return (array)$value;})->toArray();
        $arr1 = array();
        if(!empty($data1)){
            foreach($data1 as $row){
                $arr1[] = $row['project'];
            }
        }
        $data2 = (array)DB::table('members')->select('job')->where('id',$id)->first();
        $arr2 =array();
        if(!empty($data2['job'])){
            $arr2 = explode(',',$data2['job']);
        }
        return json_encode(array('r'=>1,'result'=>array('job'=>$arr1,'select'=>$arr2)));
    }

    public function add_job(){
        $id = $_POST['id'];
        $job = $_POST['job'];
        $bool = DB::table('members')->where('id',$id)->update(array('job'=>$job));
        if($bool){
            return json_encode(array('r'=>1,'msg'=>'编辑个人职业成功！'));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'编辑个人职业失败！'));
        }
    }
    //-----------------------------------------------------------------------------------------------------------------

    //----------------------------------14-15编辑档期------------------------------------------------------------------
    public function show_free_time(){
        $id = $_POST['id'];
        $log = (array)DB::table('members')->select('free_time')->where('id',$id)->first();
        return json_encode(array('r'=>1,'result'=>$log));
    }

    public function add_free_time(){
        $id = $_POST['id'];
        $free_time = $_POST['free_time'];
        $free_start = $_POST['free_start'];
        $free_end = $_POST['free_end'];
        $bool = DB::table('members')->where('id',$id)->update(array('free_time'=>$free_time,'free_start'=>$free_start,'free_end'=>$free_end));
        if($bool){
            return json_encode(array('r'=>1,'msg'=>'编辑档期成功！'));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'编辑档期失败！'));
        }
    }

    //-----------------------------------------------------------------------------------------------------------------

    //---------------------------------16.编辑个人资料-----------------------------------------------------------------
    public function showMyInfo(){
        $id = $_POST['id'];
        //查询相册视频
        $thumbs =  DB::table('thumb')->where('uid',$id)->orderby('key','asc')->get()
        ->map(function($v){return (array)$v;})->toArray();
        //查询用户基本资料
        $info = (array)DB::table('members')->leftJoin('rental_project','members.id','=','rental_project.uid')
            ->select('members.id','members.nickname','members.personal','members.age','members.height','members.weight','members.city','members.job','members.free_time','members.hobby',
            'rental_project.project','rental_project.price','rental_project.company')
            ->where('members.id',$id)->first();

        if(!empty($thumbs)){
            $info['thumb'] = $thumbs;
        }else{
            $info['thumb'] = array();
        }
        array_walk_recursive($info, function (& $val, $key ) {
            if ($val === null) {
                $val = '';
            }
        });

        return json_encode(array('r'=>1,'result'=>$info));
    }

    public function edit_info(){
        $id = $_POST['id'];
        if(!empty($_POST['nickname'])){
            $data['nickname'] = $_POST['nickname'];
        }
        if(!empty($_POST['personal'])){
            $data['personal'] = $_POST['personal'];
        }
        if(!empty($_POST['age'])){
            $data['age'] = $_POST['age'];
        }
        if(!empty($_POST['height'])){
            $data['height'] = $_POST['height'];
        }
        if(!empty($_POST['city'])){
            $data['city'] = $_POST['city'];
        }
        if(!empty($_POST['weight'])){
            $data['weight'] = $_POST['weight'];
        }

        $bool = DB::table('members')->where('id',$id)->update($data);
        if($bool){
            return json_encode(array('r'=>1,'msg'=>'修改基本信息成功！'));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'修改基本信息失败！'));
        }
    }
    //-----------------------------------------------------------------------------------------------------------------

    //---------------------------------17-19租圈发布---------------------------------------------------------------------
    public function rentCircle(){
        $data = array(
            'uid'=>$_POST['id'],
            'text'=> $_POST['text'],
            'province'=> $_POST['province'],
            'city'=> $_POST['city'],
            'lng'=> $_POST['lng'],
            'lat'=> $_POST['lat'],
            'url'=>isset($_POST['url'])?$_POST['url']:'',
            'class'=>$_POST['class'],
            'create_time'=>time()
        );
        $bool = DB::table('rent_circle')->insert($data);
        if($bool){
            return json_encode(array('r'=>1,'msg'=>'发布需求成功！'));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'发布需求失败！'));
        }

    }

    public function showNewNeed(){
        $where = ' where 1 = 1 ';
        if(isset($_POST['str']) && !empty($_POST['str'])){
            $where .= " AND (t1.id like '%".$_POST['str']."%' or t1.nickname like '%".$_POST['str']."%' or t2.text like '%".$_POST['str']."%') ";
        }
        $pagesize = 6;
        $page = isset($_POST['page']) ? $_POST['page'] : 1;
        $start = ($page-1)*$pagesize;
        $update_top_end = DB::table('rent_circle')->where('top_end','<',time())->update(array('top_end'=>null));
        $sql = "select t1.id,t1.image,t1.nickname,t1.age,t1.sex,t2.top_end,t2.province,t2.city,t2.text,t2.url,t2.class,t2.create_time from ims_members as t1 join ims_rent_circle as t2 on t1.id = t2.uid ".$where." order by t2.top_end desc ,t2.create_time desc limit {$start},{$pagesize}";
        $logs = DB::select($sql);
        if(!empty($logs)){
            foreach($logs as $k=>$v){
                $a = (array)$v;
                $logs[$k] = $a;
            }
            // array_multisort(array_column($logs,'top_end'),SORT_DESC,$logs);
        }
        array_walk_recursive($logs, function (& $val, $key ) {
            if ($val === null) {
                $val = '';
            }
        });
        if(!empty($logs)){
            return json_encode(array('r'=>1,'result'=>$logs));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'租圈暂无动态！'));
        }
    }

    public function seeLike(){
        $str = $_POST['str'];
        $logs = DB::table('members')->leftJoin('rent_circle','members.id','=','rent_circle.uid')
            ->select('members.id','members.image','members.nickname','members.age','rent_circle.province','rent_circle.city','rent_circle.text','rent_circle.url','rent_circle.create_time')
            ->where('members.id','like','%'.$str.'%')->orWhere('members.nickname','like','%'.$str.'%')->orWhere('rent_circle.text','like','%'.$str.'%')
            ->orderby('rent_circle.create_time','DESC')
            ->get()->map(function($v){return (array)$v;})->toArray();
        if(!empty($logs)){
            return json_encode(array('r'=>1,'result'=>$logs));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'没有符合条件的用户'));
        }
    }

    public function nearbyNeed(){
        $where = '';
        if(isset($_POST['str']) ){
            $where .= " AND (t1.id like '%".$_POST['str']."%' or t1.nickname like '%".$_POST['str']."%' or t2.text like '%".$_POST['str']."%') ";
        }
        $pagesize = 6;
        $page = isset($_POST['page']) ? $_POST['page'] : 1;
        $start = ($page-1)*$pagesize;
        $id = $_POST['id'];
        $lng = $_POST['lng'];//经纬度
        $lat = $_POST['lat'];
        DB::table('members')->where('id',$id)->update(array('lng'=>$lng,'lat'=>$lat));
        //取附近10W米内用户
//            $x = 0.00000681617*100000;
        //取附近1W米内用户
        $a = 0.00000680489*10000;
        $x1 = $lng+$a;
        $y1 = $lng-$a;
        $x2 = $lat+$a;
        $y2 = $lat-$a;
        $update_top_end = DB::table('rent_circle')->where('top_end','<',time())->update(array('top_end'=>null));
        $sql = "select t1.id,t1.sex,t1.age,t2.top_end,t1.image,t1.nickname,t2.lng,t2.lat,t2.province,t2.city,t2.text,t2.class,t2.url,t2.create_time from ims_members as t1 left join ims_rent_circle as t2 on t1.id = t2.uid  where t2.lng < $x1 and t2.lng > $y1 and t2.lat < $x2 and t2.lat > $y2 and t1.id !={$id} ".$where;
        $logs = DB::select($sql);
        if(!empty($logs)){
            foreach($logs as $k=>$v){
                $a = (array)$v;
                $logs[$k] = $a;
            }

            foreach($logs as $k=>$row){
                $n = floor(getdistance($lng,$lat,$row['lng'],$row['lat']))/1000;
                $logs[$k]['distance'] = sprintf("%.1f", $n).'km';
                unset($logs[$k]['lng']);
                unset($logs[$k]['lat']);
            }
            //array_column($logs,'top'),SORT_DESC,
            array_multisort(array_column($logs,'top_end'),SORT_DESC,array_column($logs,'distance'),SORT_ASC,$logs);
            $result = array_slice($logs,$start,$pagesize);
            return json_encode(array('r'=>1,'result'=>$result));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'暂无数据！'));
        }
    }
    //-----------------------------------------------------------------------------------------------------------------

    //--------------------------------------------20帮助与反馈---------------------------------------------------------
    public function feedBack(){

        $data = array(
            'uid'=>$_POST['id'],
            'type'=>$_POST['type'],
            'text'=>$_POST['text'],
            'url'=>isset($_POST['url'])?$_POST['url']:'',
            'create_time'=>time(),
        );
        $bool = DB::table('feedback')->insert($data);
        if($bool){
            return json_encode(array('r'=>1,'msg'=>'提交成功，谢谢您的反馈！'));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'提交失败！'));
        }
    }
    //-----------------------------------------------------------------------------------------------------------------

    //-------------------------------------------我的、粉丝、关注------------------------------------------------------
    public function myZone(){
        $id = $_POST['id'];
        /*$info = DB::table('members')->leftJoin('fans','members.id','=','fans.uid')
            ->select('members.id','fans.fid')
            ->where('fans.uid',$id)->get()
            ->map(function($v){return (array)$v;})->toArray();*/
        $info = (array)DB::table('members')->select('id','nickname','image')->where('id',$id)->first();
        $fans = DB::table('fans')->where('uid',$id)->get()->count();
        $follow = DB::table('fans')->where('fid',$id)->get()->count();
        $need = DB::table('rent_circle')->where('uid',$id)->count();
        $result = array(
          'info'=>$info,
            'fans'=>$fans,
            'fllow'=>$follow,
            'need'=>$need
        );
        return json_encode(array('r'=>1,'result'=>$result));
    }

    public function myNeed(){
        $id = $_POST['id'];
        $pagesize = 6;
        $page = isset($_POST['page']) ? $_POST['page'] : 1;
        $start = ($page-1)*$pagesize;
        $logs = DB::table('members')->leftJoin('rent_circle','members.id','=','rent_circle.uid')
            ->select('members.id','members.nickname','members.age','members.sex','rent_circle.text','rent_circle.url','rent_circle.province','rent_circle.city','rent_circle.create_time')
            ->where('members.id',$id)->skip($start)->take($pagesize)->get()->map(function($v){return (array)$v;})->toArray();
        if($logs){
            return json_encode(array('r'=>1,'result'=>$logs));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'还没有发布需求！'));
        }
    }

    public function myFans(){
        $followid = $_POST['id'];
        $pagesize = 6;
        $page = isset($_POST['page']) ? $_POST['page'] : 1;
        $start = ($page-1)*$pagesize;
        $info = DB::table('fans')->leftJoin('members','fans.fid','=','members.id')
            ->select('members.nickname','members.image','fans.fid','members.sex')
            ->where('fans.uid',$followid)->skip($start)->take($pagesize)->get()->map(function($v){return (array)$v;})->toArray();

        if(!empty($info)){
            foreach($info as $k=>$row){
                $bool = DB::table('fans')->where('uid',$row['fid'])->where('fid',$followid)->get()->map(function($v){return (array)$v;})->toArray();
                if(!empty($bool)){
                   $info[$k]['isMutual'] = 1;
                }else{
                   $info[$k]['isMutual'] = 0;
                }
            }
            return json_encode(array('r'=>1,'result'=>$info));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'还没有人关注我'));
        }
    }

    public function myFollow(){
        $fens_id = $_POST['id'];
        $pagesize = 6;
        $page = isset($_POST['page']) ? $_POST['page'] : 1;
        $start = ($page-1)*$pagesize;
        $info = DB::table('fans')->leftJoin('members','fans.uid','=','members.id')
            ->select('members.nickname','members.image','fans.uid','members.sex')
            ->where('fans.fid',$fens_id)->skip($start)->take($pagesize)->get()->map(function($v){return (array)$v;})->toArray();
        if($info){
            return json_encode(array('r'=>1,'result'=>$info));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'我还没有关注的人'));
        }
    }
                          //---------------增加关注---------//
    public function addFollow(){
        $fid = $_POST['id'];//当前用户ID
        $uid = $_POST['uid']; //被关注者ID
        $data = array(
            'uid' => $uid,
            'fid' => $fid,
            'create_time'=>time()
        );
        $log = (array)DB::table('fans')->where('uid',$uid)->where('fid',$fid)->first();
        if(!empty($log)){
            return json_encode(array('r'=>-1,'msg'=>'已关注过！'));
        }
        $bool = DB::table('fans')->insert($data);
        if($bool){
        $i = (array)DB::table('members')->select('fans')->where('id',$uid)->first();
        $fans = $i['fans']+1;
        DB::table('members')->where('id',$uid)->update(array('fans'=>$fans));
            return json_encode(array('r'=>1,'msg'=>'关注成功！'));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'关注失败！'));
        }
    }
                         //-------------取消关注-------------//
    public function delFollow(){
        $fid = $_POST['id'];//当前用户ID
        $uid = $_POST['uid']; //被关注者ID
        $log = (array)DB::table('fans')->where('uid',$uid)->where('fid',$fid)->first();
        if(empty($log)){
            return json_encode(array('r'=>-1,'msg'=>'不存在的关注！'));
        }
        $bool = DB::table('fans')->where('fid',$fid)->where('uid',$uid)->delete();
        if($bool){
			$i = (array)DB::table('members')->select('fans')->where('id',$uid)->first();
	        $fans = $i['fans']-1;
	        DB::table('members')->where('id',$uid)->update(array('fans'=>$fans));
            return json_encode(array('r'=>1,'msg'=>'取消关注成功！'));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'取消关注失败！'));
        }
    }


    //-----------------------------------------------------------------------------------------------------------------


    //-------------------------------显示充值界面----------------------------------------------------------------------
    public function showRecharge(){
        $logs = DB::table('project')->select('project')->where('class',8)->get()->map(function($v){return (array)$v;})->toArray();
        $data = array();
        if(!empty($logs)){
            foreach($logs as $k=> $v){
                $arr = explode('-',$v['project']);
                $data[$k]['project'] = $arr[0];
                $data[$k]['price'] = $arr[1];
            }
            return json_encode(array('r'=>1,'result'=>$data));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'暂无数据！'));
        }
    }

    public function showVip(){
        $logs = DB::table('project')->select('project')->where('class',7)->get()->map(function($v){return (array)$v;})->toArray();
        $data = array();
        if(!empty($logs)){
            foreach($logs as $k=> $v){
                $arr = explode('-',$v['project']);
                $data[$k]['project'] = $arr[0];
                $data[$k]['price'] = $arr[1];
            }
            return json_encode(array('r'=>1,'result'=>$data));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'暂无数据！'));
        }
    }

    //-----------------------------------------------------------------------------------------------------------------

    //-------------------------------------我的钱包--------------------------------------------------------------------
    public function myMoney(){
        $pagesize = 10;
        $page = isset($_POST['page']) ? $_POST['page'] : 1;
        $startPage = ($page-1)*$pagesize;
        $time = isset($_POST['time'])?$_POST['time']:date('Y-m',time());
        $id = $_POST['id'];
        $start = strtotime($time);
        $arr = explode('-', $time);
        $arr[1] = $arr[1]+1;
        $end = $arr[0].'-'.$arr[1];
        $end = strtotime($end);
        $sql = "select t2.uid,t2.fid,t2.class,t2.price,t2.create_time from ims_members as t1 left join ims_paylog as t2 on (t1.id = t2.uid or t1.id = t2.fid) where t1.id = {$id} and t2.status = 1 and t2.create_time >{$start} and t2.create_time < {$end} order by t2.create_time desc limit $startPage ,$pagesize";
        $logs = DB::select($sql);

        $sql2 = "select sum(t2.price) as total from ims_members as t1 left join ims_paylog as t2 on t1.id = t2.uid where (t2.class ='查看会员' or t2.class = '消费') and t1.id = {$id} and t2.status = 1 GROUP BY t2.uid ";
        $money = (array)DB::table('members')->select('money')->where('id',$id)->first();
        $data['money'] = $money['money'];
        $logs2 = DB::select($sql2);
        if(!empty($logs2)){
            foreach ($logs2 as $k2 => $v2) {
                $b = (array)$v2;
                $data['total'] = $b['total'];
            }
        }else{
            $data['total'] = 0.00;
        }
        if(!empty($logs)){
            foreach($logs as $k=>$v){
                $a = (array)$v;
                $data['paylog'][$k] = $a;
                if($a['uid'] == $id){
                    $data['paylog'][$k]['price'] = '+'.$data['paylog'][$k]['price'];
                }else if($a['fid'] == $id){
                    $data['paylog'][$k]['price'] = '-'.$data['paylog'][$k]['price'];
                }
                unset($data['paylog'][$k]['uid']);
                unset($data['paylog'][$k]['fid']);
            }
        }else{
            $data['paylog'] = array();
        }
        
        return json_encode(array('r'=>1,'result'=>$data));
    }

    //-----------------------------------------------------------------------------------------------------------------

    //--------------------------------------------查看用户微信---------------------------------------------------------
    public function lookAtMe(){
        $uid = $_POST['uid'];
        $pagesize = 10;
        $page = isset($_POST['page']) ? $_POST['page'] : 1;
        $startPage = ($page-1)*$pagesize;
        // $fid = $_POST['fid'];
        $sql = "select t2.nickname,t2.sex,t2.age,t2.image ,t1.create_time,t1.wx from (select * from ims_seewx ORDER BY create_time DESC limit 100000 ) t1 join ims_members as t2 on t1.fid = t2.id where t1.uid = {$uid} GROUP BY t1.fid ORDER BY t1.create_time desc limit $startPage ,$pagesize";
        $logs = DB::select($sql);
        if(!empty($logs)){
            foreach($logs as $k=>$v){
                $a = (array)$v;
                $logs[$k] = $a;
            }
            return json_encode(array('r'=>1,'result'=>$logs));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'暂无数据!'));
        }
    }

    public function iLook(){
        $fid = $_POST['fid'];
        $pagesize = 10;
        $page = isset($_POST['page']) ? $_POST['page'] : 1;
        $startPage = ($page-1)*$pagesize;
        $sql = "select t2.nickname,t2.sex,t2.age,t2.image ,t1.create_time,t1.wx from (select * from ims_seewx ORDER BY create_time DESC limit 100000 ) t1 join ims_members as t2 on t1.uid = t2.id where t1.fid = {$fid} GROUP BY t1.uid ORDER BY t1.create_time desc limit $startPage ,$pagesize";
        $logs = DB::select($sql);
        if(!empty($logs)){
            foreach($logs as $k=>$v){
                $a = (array)$v;
                $logs[$k] = $a;
            }
            return json_encode(array('r'=>1,'result'=>$logs));
        }else{
            return json_encode(array('r'=>-1,'msg'=>'暂无数据!'));
        }
    }

    //-----------------------------------------------------------------------------------------------------------------

    //-----------------------------------------认证身份----------------------------------------------------------------


    public function isId(){

    }

    public function isWx(){

    }

    public function isZm(){

    }
    //-----------------------------------------------------------------------------------------------------------------
}

